<?php
class CatView extends AbsCatView {
	private $needTpl;
	
	/**
	 * assign a value to view
	 */
	public function assign($name, $value) {
		if(isset($this->assignVals[$name])) {
			if(is_array($this->assignVals[$name])) {
				$this->assignVals[$name][] = $value;
			} else {
				$tmp = $this->assignVals[$name];
				$this->assignVals[$name] = array(
					$tmp,
					$value,
				);
			}
		} else {
			$this->assignVals[$name] = $value;
		}
	}
	
	/**
	 * fetch(all) assign values
	 */
	public function fetch($name = null) {
		$ret = false;
		
		if(null === $name) $ret = $this->assignVals;
		elseif(isset($this->assignVals[$name])) $ret = $this->assignVals[$name];
		
		return $ret;
	}
	
	/**
	 * vender the page
	 */
	public function display($framework_cat_current_tpl = '') {
		if('' === $framework_cat_current_tpl) $framework_cat_current_tpl = $this->getTplFile();
		
		# export assignVals
		$framework_cat_current_assign_number = extract($this->assignVals);
		
		$framework_cat_current_need_tpl = $this->needTpl;
		
		# require tpl
		require $framework_cat_current_tpl;
	}
	
	/**
	 * get tpl file
	 */
	private function getTplFile() {
		$actionName = getActionName();
		$methodName = getMethodName();
		$this->needTpl = $tplFile = AC('app_tpl_path') . ucfirst($actionName) . '/' . $methodName . '.html';
		if(!file_exists($tplFile)) {
			$tplFile = FRAMEWORK_TPL_ROOT . 'common.html';
		}
		
		return $tplFile;
	}
}
?>